package com.liang.lesson03;
import com.liang.lesson2.JdbcUntils;
import javax.xml.crypto.Data;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;

public class TestUpdate {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement st = null;
        try {
            conn = JdbcUntils.getConnection();
            //区别
            String sql = "update users set `NAME` =  ? where id = ?";
            st = conn.prepareStatement(sql);//预编译，先写sql，不执行
            //手动给参数赋值
            st.setString(1,"liang");
            st.setInt(2,5);
            //执行
            int i=st.executeUpdate();
            if (i>0){
                System.out.println("更新成功!!!");
            }else{
                System.out.println("更新失败!!!");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            JdbcUntils.release(conn,st,null);
        }
    }
}
